﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JEdwonTune.Lib.Validation;
using JEdwonTune.Common;

namespace JEdwonTune.Validation {
    public partial class FrmEditForm : FrmXmlNodeEditorBase {
        public FrmEditForm() {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e) {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e) {
            this.DialogResult = DialogResult.Abort;
            if (String.IsNullOrEmpty(this.txtName.Text.Trim())) {
                MessageBox.Show("请输入Name");
                return;
            }
            SetNodeAttrValue(base.Node, "name", this.txtName.Text.Trim());
            SetNodeAttrValue(base.Node, "client-prefix", this.txtClientPrefix.Text.Trim());
            SetNodeAttrValue(base.Node, "inform", this.cbxInform.SelectedValue.ToString());
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void FrmEditForm_Load(object sender, EventArgs e) {
            if (base.Node == null) {
                return;
            }
            if (base.Node.Name != "form") {
                MessageBox.Show("编辑的节点不是form节点");
                this.Close();
                return;
            }
            this.cbxInform.DataSource = Ctrls.InformItems();
            this.cbxInform.DisplayMember = "Value";
            this.cbxInform.ValueMember = "Key";
            if (base.Node.Attributes["name"] != null) {
                this.txtName.Text = base.Node.Attributes["name"].Value;
            }
            if (base.Node.Attributes["client-prefix"] != null) {
                this.txtClientPrefix.Text = base.Node.Attributes["client-prefix"].Value;
            }
            if (base.Node.Attributes["inform"] != null) {
                this.cbxInform.SelectedValue = base.Node.Attributes["inform"].Value;
            }
        }
    }
}
